<?php

namespace App\Models;

/**
 * App\Models\Category
 *
 * @property int $id
 * @property int $user_id 所属用户id
 * @property string $category_name 分类名称
 * @property int $sort 同级别排序
 * @property int $card_num 冗余 卡片数量(包含所有子集的数量)
 * @property int $wait_card_num 冗余 待复习的卡片数量(包含所有子集)
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card[] $card
 * @property-read int|null $card_count
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|Category newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Category newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Model orderCheck($request)
 * @method static \Illuminate\Database\Eloquent\Builder|Model pageCheck($request, $field = [], $makeVisible = [])
 * @method static \Illuminate\Database\Eloquent\Builder|Category query()
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereCardNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereCategoryName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Category whereWaitCardNum($value)
 * @mixin \Eloquent
 */
class Category extends Model
{
    protected $table = 'category';

    protected $primaryKey = 'id';

    protected $fillable = ['category_name', 'sort'];

    /**
     * 常量定义
     */
    const CATEGORY_DEFAULT_NAME = '默认笔记本';

    /*
     * 模型关联
     */
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public function card()
    {
        return $this->hasMany(Card::class,'category_id','id');
    }
}
